//
//  PPContactsModel.m
//  
//
//  Created by Jinxiao on 8/28/16.
//
//

#import "PPContactsModel.h"

@implementation PPContactsModel

// Insert code here to add functionality to your managed object subclass

+ (instancetype)existingFanForUserID:(PPUserID)userID relationShip:(NSNumber *)relationShip
{
    PPContactsModel *contact = [self find:@{@"userID" : userID, @"currentUserID" : DGCurrentAccount.userID, @"relationship" : relationShip}];

    if(contact == nil) {
        contact = [PPContactsModel create];
        contact.userID = userID;
        contact.currentUserID = DGCurrentAccount.userID;
        contact.relationship = relationShip;
        [contact.managedObjectContext saveContext];
    }

    return contact;
}

- (NSString *)avatarURLString {
    if(self.avatar.length == 0 || self.avatarHost.length == 0) {
        return nil;
    }

    if([self.avatar hasPrefix:@"http:"]) {
        return self.avatar;
    }

    return [NSString stringWithFormat:@"%@%@", self.avatarHost, self.avatar];
}

@end
